package com.pd.controller;

import com.pd.pojo.Item;
import com.pd.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    // ?key=&page=1&size=20
    @GetMapping("/search/toSearch.html")
    public String search(Model model,String key, Pageable pageable) {

        Page<Item> page = searchService.search(key, pageable);
        model.addAttribute("page", page);

        return "/search.jsp";

    }

}
